package com.company;

import com.company.prototype.CarByShallow;

/**
 * 原型模式-浅拷贝测试
 */
public class TestForShallow {

    public static void main(String[] args)  throws CloneNotSupportedException {
        //原始对象
        CarByShallow car = new CarByShallow();
        car.setName("雅阁");
        car.setLength(4906);  //单位mm
        car.getModelList().add("锐领版");

        //浅拷贝
        CarByShallow carByCopy = car.clone();
        carByCopy.setName("宝马5系");
        carByCopy.setLength(5106);  //单位mm
        carByCopy.getModelList().clear();
        carByCopy.getModelList().add("运动版");

        System.out.println("原始对象="+car+"，名称="+car.getName()+", 车长="+car.getLength()+"mm, 包含型号="+car.getModelList().toString());
        System.out.println("浅拷贝对象="+carByCopy+"，名称="+carByCopy.getName()+", 车长="+carByCopy.getLength()+"mm, 包含型号="+carByCopy.getModelList().toString());
    }
}
